package com.yc.yc112plyqnzf.controller;


import com.yc.yc112plyqnzf.entity.Users;
import com.yc.yc112plyqnzf.mapper.UsersMapper;
import com.yc.yc112plyqnzf.vo.Result;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.lang.ref.ReferenceQueue;
import java.util.List;

/**
 * <p>
 * 青鸟租房-用户表-1003 前端控制器
 * </p>
 *
 * @author yc
 * @since 2022-09-03
 */
@RestController
@RequestMapping("/yc112plyqnzf/users")
public class UsersController {
    @Resource
    private UsersMapper usersMapper;

    @GetMapping("login")
    public Result login(HttpServletRequest request, String username, String password){
        System.out.println(username);
        System.out.println(password);
        List<Users> users = usersMapper.selectList(null);
       for(int i=0;i<users.size();i++){
           if(users.get(i).getUsername().equals(username)&&users.get(i).getPassword().equals(password)){
               HttpSession session = request.getSession();
               session.setAttribute("username",users.get(i).getUsername());
               session.setAttribute("password",users.get(i).getPassword());
               return  new Result(1,"登录成功",null);
           }
       }

       return  new Result(0,"账户或密码错误，请重新输入",null);
    }

}

